﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.MediaCenter.Hosting;
using Microsoft.MediaCenter;

namespace RMC.Commands
{
	internal class GotoCommand : ICommand
	{

		#region ICommand Members

		public string Syntax
		{
			get { return "goto <ExtensibilityUrl|FMRadio|InternetRadio|LiveTV|ManageDisks|MovieLibrary|MorePrograms|MusicAlbums|MusicArtists|MusicSongs|MyMusic|MyPictures|MyTV|MyVideos|PhotoDetails|RecordedTV|RecorderStorageSettings|ScheduledTVRecordings|Slideshow|SlideshowSettings|Start|TVGuide|Visualizations|WebAddIn> [params]"; }
		}

		public string Help
		{
			get
			{
				return @"goto <ExtensibilityUrl|FMRadio|InternetRadio|LiveTV|ManageDisks|MovieLibrary|MorePrograms|MusicAlbums|MusicArtists|MusicSongs|MyMusic|MyPictures|MyTV|MyVideos|PhotoDetails|RecordedTV|RecorderStorageSettings|ScheduledTVRecordings|Slideshow|SlideshowSettings|Start|TVGuide|Visualizations|WebAddIn> [params]

Determine the params
----------------------------------------------------
ExtensibilityUrl        = URL of the destination page.
FMRadio                 = Null
InternetRadio           = Null
LiveTV                  = Null
ManageDisks             = Null
MorePrograms            = Null
MovieLibrary            = Null
MusicAlbums             = Null
MusicArtists            = Null
MusicSongs              = Null
MyMusic                 = Null
MyPictures              = Path to folder
MyTV                    = Null
MyVideos                = Path to folder
PhotoDetails            = Path to the photo for which the application should show details.
RecordedTV              = Null
RecorderStorageSettings = Null
ScheduledTVRecordings   = Null
Slideshow               = Path to folder
SlideshowSettings       = Null
Start                   = Null
TVGuide                 = Null
Visualizations          = visualizationName:preset
WebAddIn                = URL of the destination page.
";
			}
		}

		public CommandResult Execute(string args)
		{
			CommandResult cr = new CommandResult();

			string[] array = args.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length >= 1)
			{
				PageId page = PageId.Start;
				
				try
				{
					page = (PageId)Enum.Parse(typeof(PageId), array[0], true);

				}
				catch (Exception)
				{
					cr.Type = CommandResultType.BadArguments;
					cr.Content = "Page not found";
					return cr;
				}

				object param = null;
				if (array.Length == 2)
					param = array[1];

				try
				{
					AddInHost.Current.MediaCenterEnvironment.NavigateToPage(page, param);
				}
				catch (Exception ex)
				{
					cr.Type = CommandResultType.Exception;
					cr.Content = ex.Message;
					return cr;
				}

				cr.Type = CommandResultType.Executed;

			}
			else
			{	
				cr.Type = CommandResultType.BadArguments;
				cr.Content = "Page not specified";
			}

			return cr;
		}

		#endregion
	}
}
